package com.example.yjhmatch.controller;


import com.example.yjhmatch.mapper.ResultsMapper;
import com.example.yjhmatch.service.IResultsService;
import com.yc.yjh.entity.Result;
import com.yc.yjh.entity.Results;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 赛事结果表 前端控制器
 * </p>
 *
 * @author 廖老师
 * @since 2023-07-24
 */
@RestController
@RequestMapping("/results/results")
public class ResultsController {
    @Resource
    ResultsMapper resultsMapper;
    @Resource
    IResultsService resultsService;
    @RequestMapping("selectResultsCount")
    public int selectResultsCount(){
        return resultsMapper.selectResultsCount();
    }

    @RequestMapping("addResult")
    public Result addResult(@RequestBody Results result){
        resultsService.saveOrUpdate(result);
        return Result.success("添加成功");
    }
    @RequestMapping("selectAllResult")
    public List selectAllResult(){
        return resultsService.list();
    }

    @RequestMapping("selectByMid")
    public Result selectByMid(@RequestParam("mid") String mid){
        List list;
        if (mid!=null&&!mid.trim().isEmpty()){
            list=resultsService.lambdaQuery()
                    .eq(Results::getMatchId,mid).list();
        }else{
            list=resultsService.list();
        }
        if (list.isEmpty()){
            return Result.error(0,"查询失败，请检查比赛是否存在");
        }else {
            return Result.success("查询成功",list);
        }
    }
}

